{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import scipy as sp\n",
    "from sklearn.metrics import r2_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rmse(y_test, y):\n",
    "\treturn sp.sqrt(sp.mean((y_test - y) ** 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv(\"/Users/ys/Documents/csdn/code/01_week_homework/day.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>dteday</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2011-01-01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2011-01-02</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2011-01-03</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2011-01-04</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2011-01-05</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
       "0        1  2011-01-01       1   0     1        0        6           0   \n",
       "1        2  2011-01-02       1   0     1        0        0           0   \n",
       "2        3  2011-01-03       1   0     1        0        1           1   \n",
       "3        4  2011-01-04       1   0     1        0        2           1   \n",
       "4        5  2011-01-05       1   0     1        0        3           1   \n",
       "\n",
       "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
       "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
       "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
       "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
       "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
       "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
       "\n",
       "    cnt  \n",
       "0   985  \n",
       "1   801  \n",
       "2  1349  \n",
       "3  1562  \n",
       "4  1600  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 731 entries, 0 to 730\n",
      "Data columns (total 16 columns):\n",
      "instant       731 non-null int64\n",
      "dteday        731 non-null object\n",
      "season        731 non-null int64\n",
      "yr            731 non-null int64\n",
      "mnth          731 non-null int64\n",
      "holiday       731 non-null int64\n",
      "weekday       731 non-null int64\n",
      "workingday    731 non-null int64\n",
      "weathersit    731 non-null int64\n",
      "temp          731 non-null float64\n",
      "atemp         731 non-null float64\n",
      "hum           731 non-null float64\n",
      "windspeed     731 non-null float64\n",
      "casual        731 non-null int64\n",
      "registered    731 non-null int64\n",
      "cnt           731 non-null int64\n",
      "dtypes: float64(4), int64(11), object(1)\n",
      "memory usage: 91.4+ KB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = train[\"cnt\"]\n",
    "X = train.drop([\"cnt\"], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.get_dummies(train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>...</th>\n",
       "      <th>dteday_2012-12-22</th>\n",
       "      <th>dteday_2012-12-23</th>\n",
       "      <th>dteday_2012-12-24</th>\n",
       "      <th>dteday_2012-12-25</th>\n",
       "      <th>dteday_2012-12-26</th>\n",
       "      <th>dteday_2012-12-27</th>\n",
       "      <th>dteday_2012-12-28</th>\n",
       "      <th>dteday_2012-12-29</th>\n",
       "      <th>dteday_2012-12-30</th>\n",
       "      <th>dteday_2012-12-31</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 746 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant  season  yr  mnth  holiday  weekday  workingday  weathersit  \\\n",
       "0        1       1   0     1        0        6           0           2   \n",
       "1        2       1   0     1        0        0           0           2   \n",
       "2        3       1   0     1        0        1           1           1   \n",
       "3        4       1   0     1        0        2           1           1   \n",
       "4        5       1   0     1        0        3           1           1   \n",
       "\n",
       "       temp     atemp        ...          dteday_2012-12-22  \\\n",
       "0  0.344167  0.363625        ...                          0   \n",
       "1  0.363478  0.353739        ...                          0   \n",
       "2  0.196364  0.189405        ...                          0   \n",
       "3  0.200000  0.212122        ...                          0   \n",
       "4  0.226957  0.229270        ...                          0   \n",
       "\n",
       "   dteday_2012-12-23  dteday_2012-12-24  dteday_2012-12-25  dteday_2012-12-26  \\\n",
       "0                  0                  0                  0                  0   \n",
       "1                  0                  0                  0                  0   \n",
       "2                  0                  0                  0                  0   \n",
       "3                  0                  0                  0                  0   \n",
       "4                  0                  0                  0                  0   \n",
       "\n",
       "   dteday_2012-12-27  dteday_2012-12-28  dteday_2012-12-29  dteday_2012-12-30  \\\n",
       "0                  0                  0                  0                  0   \n",
       "1                  0                  0                  0                  0   \n",
       "2                  0                  0                  0                  0   \n",
       "3                  0                  0                  0                  0   \n",
       "4                  0                  0                  0                  0   \n",
       "\n",
       "   dteday_2012-12-31  \n",
       "0                  0  \n",
       "1                  0  \n",
       "2                  0  \n",
       "3                  0  \n",
       "4                  0  \n",
       "\n",
       "[5 rows x 746 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = train\n",
    "columns = X.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(584, 746)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 分离数据\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10, test_size=0.20)\n",
    "X_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "ss_X = StandardScaler()\n",
    "ss_y = StandardScaler()\n",
    "\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test = ss_X.transform(X_test)\n",
    "\n",
    "y_train = np.array(y_train)\n",
    "y_test = np.array(y_test)\n",
    "\n",
    "y_train = ss_y.fit_transform(y_train.reshape(-1, 1))\n",
    "y_test = ss_y.transform(y_test.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "lr = LinearRegression()\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "y_test_pred_lr = lr.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# OLS回归\n",
    "import statsmodels.api as sm\n",
    "ols=sm.OLS(y_train, X_train)\n",
    "ols=ols.fit()\n",
    "# ols.params\n",
    "# ols.summary()\n",
    "y_train_pred_ols = ols.predict(X_train)\n",
    "y_test_pred_ols = ols.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# RidgeCV岭回归\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "alphas = [0.01, 0.1, 1]\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)\n",
    "ridge.fit(X_train, y_train)\n",
    "\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "y_test_pred_ridge = ridge.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/ys/anaconda3/lib/python2.7/site-packages/sklearn/linear_model/coordinate_descent.py:1109: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n",
      "/Users/ys/anaconda3/lib/python2.7/site-packages/sklearn/linear_model/coordinate_descent.py:492: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n"
     ]
    }
   ],
   "source": [
    "# LassoCV回归\n",
    "from sklearn.linear_model import LassoCV\n",
    "lasso = LassoCV()\n",
    "lasso.fit(X_train, y_train)\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ols</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.152106</td>\n",
       "      <td>[0.23144343429535594]</td>\n",
       "      <td>0.228149</td>\n",
       "      <td>[0.21865735853865167]</td>\n",
       "      <td>cnt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.691122</td>\n",
       "      <td>[0.2234204553147892]</td>\n",
       "      <td>0.221008</td>\n",
       "      <td>[0.21146557464503357]</td>\n",
       "      <td>registered</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.285060</td>\n",
       "      <td>[0.1381480792569772]</td>\n",
       "      <td>0.139771</td>\n",
       "      <td>[0.1369370228319453]</td>\n",
       "      <td>casual</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.12280687263265547]</td>\n",
       "      <td>0.128662</td>\n",
       "      <td>[0.09902549091249523]</td>\n",
       "      <td>yr</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.08331422764271303]</td>\n",
       "      <td>0.083527</td>\n",
       "      <td>[0.08595825059725525]</td>\n",
       "      <td>atemp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.08043975554888474]</td>\n",
       "      <td>0.077271</td>\n",
       "      <td>[0.08352358797518655]</td>\n",
       "      <td>temp</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.059937370491983055]</td>\n",
       "      <td>0.054382</td>\n",
       "      <td>[0.047482906590252304]</td>\n",
       "      <td>season</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>456</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.02892465400349368]</td>\n",
       "      <td>0.028624</td>\n",
       "      <td>[0.02887822427603939]</td>\n",
       "      <td>dteday_2012-03-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>652</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.025765847598590914]</td>\n",
       "      <td>0.025784</td>\n",
       "      <td>[0.025190095742487643]</td>\n",
       "      <td>dteday_2012-09-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>645</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.024533069117008886]</td>\n",
       "      <td>0.024582</td>\n",
       "      <td>[0.023417569962988286]</td>\n",
       "      <td>dteday_2012-09-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>632</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.02384400128404634]</td>\n",
       "      <td>0.023651</td>\n",
       "      <td>[0.02297937997014522]</td>\n",
       "      <td>dteday_2012-09-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>644</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.02371955230507736]</td>\n",
       "      <td>0.023758</td>\n",
       "      <td>[0.022627056215033223]</td>\n",
       "      <td>dteday_2012-09-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>533</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.023598613431553013]</td>\n",
       "      <td>0.023314</td>\n",
       "      <td>[0.023241591432006433]</td>\n",
       "      <td>dteday_2012-06-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>536</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.022377405762362364]</td>\n",
       "      <td>0.022289</td>\n",
       "      <td>[0.021870468879200494]</td>\n",
       "      <td>dteday_2012-06-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[0.021620360559810554]</td>\n",
       "      <td>0.022781</td>\n",
       "      <td>[0.023641830263962136]</td>\n",
       "      <td>workingday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.021465945202595295]</td>\n",
       "      <td>0.021591</td>\n",
       "      <td>[0.02066844069946805]</td>\n",
       "      <td>dteday_2012-10-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.021360708285195422]</td>\n",
       "      <td>0.024658</td>\n",
       "      <td>[0.008109536994297365]</td>\n",
       "      <td>mnth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>642</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.021200938187939715]</td>\n",
       "      <td>0.021065</td>\n",
       "      <td>[0.020044898696553307]</td>\n",
       "      <td>dteday_2012-09-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>519</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.021123347864059522]</td>\n",
       "      <td>0.020656</td>\n",
       "      <td>[0.020755439677143776]</td>\n",
       "      <td>dteday_2012-05-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>669</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.020801694875420926]</td>\n",
       "      <td>0.020782</td>\n",
       "      <td>[0.019863521520052344]</td>\n",
       "      <td>dteday_2012-10-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>635</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.02069552623696701]</td>\n",
       "      <td>0.020676</td>\n",
       "      <td>[0.019665595719595818]</td>\n",
       "      <td>dteday_2012-09-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>673</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.020501382064971187]</td>\n",
       "      <td>0.020248</td>\n",
       "      <td>[0.01943787998680919]</td>\n",
       "      <td>dteday_2012-10-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>518</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.020402195110367297]</td>\n",
       "      <td>0.020176</td>\n",
       "      <td>[0.0199999595611797]</td>\n",
       "      <td>dteday_2012-05-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>490</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.02035770486862233]</td>\n",
       "      <td>0.020296</td>\n",
       "      <td>[0.020140029536710014]</td>\n",
       "      <td>dteday_2012-04-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>678</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.01992415618294088]</td>\n",
       "      <td>0.020134</td>\n",
       "      <td>[0.018724785955249238]</td>\n",
       "      <td>dteday_2012-10-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>538</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.019842495339776844]</td>\n",
       "      <td>0.019703</td>\n",
       "      <td>[0.019274503673932762]</td>\n",
       "      <td>dteday_2012-06-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>637</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.019699279743723166]</td>\n",
       "      <td>0.019638</td>\n",
       "      <td>[0.01853981216794974]</td>\n",
       "      <td>dteday_2012-09-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>670</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.019548411384056504]</td>\n",
       "      <td>0.019470</td>\n",
       "      <td>[0.01848531585612725]</td>\n",
       "      <td>dteday_2012-10-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.019445258218733358]</td>\n",
       "      <td>0.019211</td>\n",
       "      <td>[0.018401105814254762]</td>\n",
       "      <td>dteday_2012-09-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>517</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[0.01940503450255108]</td>\n",
       "      <td>0.019308</td>\n",
       "      <td>[0.018958043807680753]</td>\n",
       "      <td>dteday_2012-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.01814798926747012]</td>\n",
       "      <td>-0.018127</td>\n",
       "      <td>[-0.018248813015016616]</td>\n",
       "      <td>dteday_2011-11-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>744</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.018431184439842437]</td>\n",
       "      <td>-0.019836</td>\n",
       "      <td>[-0.024328927590107505]</td>\n",
       "      <td>dteday_2012-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.018508343329792905]</td>\n",
       "      <td>-0.019135</td>\n",
       "      <td>[-0.021099667160627236]</td>\n",
       "      <td>dteday_2012-02-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>340</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.018600530433774597]</td>\n",
       "      <td>-0.018097</td>\n",
       "      <td>[-0.01878692503246753]</td>\n",
       "      <td>dteday_2011-11-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>264</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.018815942484021998]</td>\n",
       "      <td>-0.018280</td>\n",
       "      <td>[-0.01852518317676586]</td>\n",
       "      <td>dteday_2011-09-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>224</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.019046137219893063]</td>\n",
       "      <td>-0.018436</td>\n",
       "      <td>[-0.018087622474243014]</td>\n",
       "      <td>dteday_2011-07-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>569</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-0.019322935802007113]</td>\n",
       "      <td>-0.019592</td>\n",
       "      <td>[-0.02155128737054446]</td>\n",
       "      <td>dteday_2012-07-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>219</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.019498686350634665]</td>\n",
       "      <td>-0.018879</td>\n",
       "      <td>[-0.018417552348928858]</td>\n",
       "      <td>dteday_2011-07-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>736</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.019600586719229263]</td>\n",
       "      <td>-0.021057</td>\n",
       "      <td>[-0.025445128331886214]</td>\n",
       "      <td>dteday_2012-12-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>265</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.019831870494731178]</td>\n",
       "      <td>-0.019196</td>\n",
       "      <td>[-0.019669412967942057]</td>\n",
       "      <td>dteday_2011-09-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>280</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.021121142271214973]</td>\n",
       "      <td>-0.020403</td>\n",
       "      <td>[-0.02065226551214338]</td>\n",
       "      <td>dteday_2011-09-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.022059533243554672]</td>\n",
       "      <td>-0.022659</td>\n",
       "      <td>[-0.025854394047791898]</td>\n",
       "      <td>dteday_2012-11-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>372</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02217474437967498]</td>\n",
       "      <td>-0.022842</td>\n",
       "      <td>[-0.024491720038366676]</td>\n",
       "      <td>dteday_2011-12-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>708</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02266079911277278]</td>\n",
       "      <td>-0.023346</td>\n",
       "      <td>[-0.02660189086663759]</td>\n",
       "      <td>dteday_2012-11-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>737</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.022716141624031946]</td>\n",
       "      <td>-0.024261</td>\n",
       "      <td>[-0.028619333930819512]</td>\n",
       "      <td>dteday_2012-12-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02309620534676015]</td>\n",
       "      <td>-0.023232</td>\n",
       "      <td>[-0.021981013302212127]</td>\n",
       "      <td>dteday_2011-01-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>739</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.023149487988240208]</td>\n",
       "      <td>-0.024658</td>\n",
       "      <td>[-0.02920020675870882]</td>\n",
       "      <td>dteday_2012-12-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>342</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.023227614447765048]</td>\n",
       "      <td>-0.023104</td>\n",
       "      <td>[-0.023423220134440648]</td>\n",
       "      <td>dteday_2011-11-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02349327348767803]</td>\n",
       "      <td>-0.023903</td>\n",
       "      <td>[-0.022417861971736158]</td>\n",
       "      <td>dteday_2011-03-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.024162234535731627]</td>\n",
       "      <td>-0.026810</td>\n",
       "      <td>[-0.02374937472593678]</td>\n",
       "      <td>hum</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>740</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02485738451823746]</td>\n",
       "      <td>-0.026184</td>\n",
       "      <td>[-0.031325391357236346]</td>\n",
       "      <td>dteday_2012-12-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>355</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.0253602074699366]</td>\n",
       "      <td>-0.024925</td>\n",
       "      <td>[-0.026103469543707757]</td>\n",
       "      <td>dteday_2011-12-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>217</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.025421277286139916]</td>\n",
       "      <td>-0.024848</td>\n",
       "      <td>[-0.024655781397961762]</td>\n",
       "      <td>dteday_2011-07-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>706</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.025551857573441913]</td>\n",
       "      <td>-0.026459</td>\n",
       "      <td>[-0.02942871120328016]</td>\n",
       "      <td>dteday_2012-11-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>738</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02853270505437493]</td>\n",
       "      <td>-0.030273</td>\n",
       "      <td>[-0.03497742359801377]</td>\n",
       "      <td>dteday_2012-12-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>253</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.02970285026585267]</td>\n",
       "      <td>-0.028992</td>\n",
       "      <td>[-0.029970157230347256]</td>\n",
       "      <td>dteday_2011-08-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>683</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.032860281099346106]</td>\n",
       "      <td>-0.033386</td>\n",
       "      <td>[-0.03725157042301495]</td>\n",
       "      <td>dteday_2012-10-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.03338802867643127]</td>\n",
       "      <td>-0.034897</td>\n",
       "      <td>[-0.03417466508608057]</td>\n",
       "      <td>windspeed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>682</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.04207540000230876]</td>\n",
       "      <td>-0.042206</td>\n",
       "      <td>[-0.046987439919085716]</td>\n",
       "      <td>dteday_2012-10-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-0.049993084230358045]</td>\n",
       "      <td>-0.050880</td>\n",
       "      <td>[-0.05234752725338635]</td>\n",
       "      <td>weathersit</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>746 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     coef_lasso                  coef_lr  coef_ols               coef_ridge  \\\n",
       "14     0.152106    [0.23144343429535594]  0.228149    [0.21865735853865167]   \n",
       "13     0.691122     [0.2234204553147892]  0.221008    [0.21146557464503357]   \n",
       "12     0.285060     [0.1381480792569772]  0.139771     [0.1369370228319453]   \n",
       "2      0.000000    [0.12280687263265547]  0.128662    [0.09902549091249523]   \n",
       "9      0.000000    [0.08331422764271303]  0.083527    [0.08595825059725525]   \n",
       "8      0.000000    [0.08043975554888474]  0.077271    [0.08352358797518655]   \n",
       "1      0.000000   [0.059937370491983055]  0.054382   [0.047482906590252304]   \n",
       "456    0.000000    [0.02892465400349368]  0.028624    [0.02887822427603939]   \n",
       "652    0.000000   [0.025765847598590914]  0.025784   [0.025190095742487643]   \n",
       "645    0.000000   [0.024533069117008886]  0.024582   [0.023417569962988286]   \n",
       "632    0.000000    [0.02384400128404634]  0.023651    [0.02297937997014522]   \n",
       "644    0.000000    [0.02371955230507736]  0.023758   [0.022627056215033223]   \n",
       "533    0.000000   [0.023598613431553013]  0.023314   [0.023241591432006433]   \n",
       "536    0.000000   [0.022377405762362364]  0.022289   [0.021870468879200494]   \n",
       "6     -0.000000   [0.021620360559810554]  0.022781   [0.023641830263962136]   \n",
       "663    0.000000   [0.021465945202595295]  0.021591    [0.02066844069946805]   \n",
       "3      0.000000   [0.021360708285195422]  0.024658   [0.008109536994297365]   \n",
       "642    0.000000   [0.021200938187939715]  0.021065   [0.020044898696553307]   \n",
       "519    0.000000   [0.021123347864059522]  0.020656   [0.020755439677143776]   \n",
       "669    0.000000   [0.020801694875420926]  0.020782   [0.019863521520052344]   \n",
       "635    0.000000    [0.02069552623696701]  0.020676   [0.019665595719595818]   \n",
       "673    0.000000   [0.020501382064971187]  0.020248    [0.01943787998680919]   \n",
       "518    0.000000   [0.020402195110367297]  0.020176     [0.0199999595611797]   \n",
       "490    0.000000    [0.02035770486862233]  0.020296   [0.020140029536710014]   \n",
       "678    0.000000    [0.01992415618294088]  0.020134   [0.018724785955249238]   \n",
       "538    0.000000   [0.019842495339776844]  0.019703   [0.019274503673932762]   \n",
       "637    0.000000   [0.019699279743723166]  0.019638    [0.01853981216794974]   \n",
       "670    0.000000   [0.019548411384056504]  0.019470    [0.01848531585612725]   \n",
       "634    0.000000   [0.019445258218733358]  0.019211   [0.018401105814254762]   \n",
       "517    0.000000    [0.01940503450255108]  0.019308   [0.018958043807680753]   \n",
       "..          ...                      ...       ...                      ...   \n",
       "343   -0.000000   [-0.01814798926747012] -0.018127  [-0.018248813015016616]   \n",
       "744   -0.000000  [-0.018431184439842437] -0.019836  [-0.024328927590107505]   \n",
       "439   -0.000000  [-0.018508343329792905] -0.019135  [-0.021099667160627236]   \n",
       "340   -0.000000  [-0.018600530433774597] -0.018097   [-0.01878692503246753]   \n",
       "264   -0.000000  [-0.018815942484021998] -0.018280   [-0.01852518317676586]   \n",
       "224   -0.000000  [-0.019046137219893063] -0.018436  [-0.018087622474243014]   \n",
       "569    0.000000  [-0.019322935802007113] -0.019592   [-0.02155128737054446]   \n",
       "219   -0.000000  [-0.019498686350634665] -0.018879  [-0.018417552348928858]   \n",
       "736   -0.000000  [-0.019600586719229263] -0.021057  [-0.025445128331886214]   \n",
       "265   -0.000000  [-0.019831870494731178] -0.019196  [-0.019669412967942057]   \n",
       "280   -0.000000  [-0.021121142271214973] -0.020403   [-0.02065226551214338]   \n",
       "709   -0.000000  [-0.022059533243554672] -0.022659  [-0.025854394047791898]   \n",
       "372   -0.000000   [-0.02217474437967498] -0.022842  [-0.024491720038366676]   \n",
       "708   -0.000000   [-0.02266079911277278] -0.023346   [-0.02660189086663759]   \n",
       "737   -0.000000  [-0.022716141624031946] -0.024261  [-0.028619333930819512]   \n",
       "41    -0.000000   [-0.02309620534676015] -0.023232  [-0.021981013302212127]   \n",
       "739   -0.000000  [-0.023149487988240208] -0.024658   [-0.02920020675870882]   \n",
       "342   -0.000000  [-0.023227614447765048] -0.023104  [-0.023423220134440648]   \n",
       "83    -0.000000   [-0.02349327348767803] -0.023903  [-0.022417861971736158]   \n",
       "10    -0.000000  [-0.024162234535731627] -0.026810   [-0.02374937472593678]   \n",
       "740   -0.000000   [-0.02485738451823746] -0.026184  [-0.031325391357236346]   \n",
       "355   -0.000000    [-0.0253602074699366] -0.024925  [-0.026103469543707757]   \n",
       "217   -0.000000  [-0.025421277286139916] -0.024848  [-0.024655781397961762]   \n",
       "706   -0.000000  [-0.025551857573441913] -0.026459   [-0.02942871120328016]   \n",
       "738   -0.000000   [-0.02853270505437493] -0.030273   [-0.03497742359801377]   \n",
       "253   -0.000000   [-0.02970285026585267] -0.028992  [-0.029970157230347256]   \n",
       "683   -0.000000  [-0.032860281099346106] -0.033386   [-0.03725157042301495]   \n",
       "11    -0.000000   [-0.03338802867643127] -0.034897   [-0.03417466508608057]   \n",
       "682   -0.000000   [-0.04207540000230876] -0.042206  [-0.046987439919085716]   \n",
       "7     -0.000000  [-0.049993084230358045] -0.050880   [-0.05234752725338635]   \n",
       "\n",
       "               columns  \n",
       "14                 cnt  \n",
       "13          registered  \n",
       "12              casual  \n",
       "2                   yr  \n",
       "9                atemp  \n",
       "8                 temp  \n",
       "1               season  \n",
       "456  dteday_2012-03-17  \n",
       "652  dteday_2012-09-29  \n",
       "645  dteday_2012-09-22  \n",
       "632  dteday_2012-09-09  \n",
       "644  dteday_2012-09-21  \n",
       "533  dteday_2012-06-02  \n",
       "536  dteday_2012-06-05  \n",
       "6           workingday  \n",
       "663  dteday_2012-10-10  \n",
       "3                 mnth  \n",
       "642  dteday_2012-09-19  \n",
       "519  dteday_2012-05-19  \n",
       "669  dteday_2012-10-16  \n",
       "635  dteday_2012-09-12  \n",
       "673  dteday_2012-10-20  \n",
       "518  dteday_2012-05-18  \n",
       "490  dteday_2012-04-20  \n",
       "678  dteday_2012-10-25  \n",
       "538  dteday_2012-06-07  \n",
       "637  dteday_2012-09-14  \n",
       "670  dteday_2012-10-17  \n",
       "634  dteday_2012-09-11  \n",
       "517  dteday_2012-05-17  \n",
       "..                 ...  \n",
       "343  dteday_2011-11-25  \n",
       "744  dteday_2012-12-30  \n",
       "439  dteday_2012-02-29  \n",
       "340  dteday_2011-11-22  \n",
       "264  dteday_2011-09-07  \n",
       "224  dteday_2011-07-29  \n",
       "569  dteday_2012-07-08  \n",
       "219  dteday_2011-07-24  \n",
       "736  dteday_2012-12-22  \n",
       "265  dteday_2011-09-08  \n",
       "280  dteday_2011-09-23  \n",
       "709  dteday_2012-11-25  \n",
       "372  dteday_2011-12-24  \n",
       "708  dteday_2012-11-24  \n",
       "737  dteday_2012-12-23  \n",
       "41   dteday_2011-01-27  \n",
       "739  dteday_2012-12-25  \n",
       "342  dteday_2011-11-24  \n",
       "83   dteday_2011-03-10  \n",
       "10                 hum  \n",
       "740  dteday_2012-12-26  \n",
       "355  dteday_2011-12-07  \n",
       "217  dteday_2011-07-22  \n",
       "706  dteday_2012-11-22  \n",
       "738  dteday_2012-12-24  \n",
       "253  dteday_2011-08-27  \n",
       "683  dteday_2012-10-30  \n",
       "11           windspeed  \n",
       "682  dteday_2012-10-29  \n",
       "7           weathersit  \n",
       "\n",
       "[746 rows x 5 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 特征系数\n",
    "fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ols\":list((ols.params.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('LinearRegression-train-rmse-score: ', 1.6868468760397186e-15)\n",
      "('LinearRegression-test-rmse-score: ', 0.2608710073563875)\n",
      "('LinearRegression-train-r2score: ', 1.0)\n",
      "('LinearRegression-test-r2score: ', 0.9332406231827579)\n",
      "('OLS-train-rmse-score: ', 1.4146699428212766)\n",
      "('OLS-test-rmse-score: ', 1.284398330824126)\n",
      "('OLS-train-r2score: ', 0.9999971150065713)\n",
      "('OLS-test-r2score: ', 0.9335132751437458)\n",
      "('RidgeCV-train-rmse-score: ', 4.447968679698035e-06)\n",
      "('RidgeCV-test-rmse-score: ', 0.2596024116150097)\n",
      "('RidgeCV-train-r2score: ', 0.9999999999802156)\n",
      "('RidgeCV-test-r2score: ', 0.9338883359346055)\n",
      "('LassoCV-train-rmse-score: ', 1.4135066811949089)\n",
      "('LassoCV-test-rmse-score: ', 1.4270726581430864)\n",
      "('LassoCV-train-r2score: ', 0.999998862217354)\n",
      "('LassoCV-test-r2score ', 0.9999985833238034)\n"
     ]
    }
   ],
   "source": [
    "# LR评价得分\n",
    "print ('LinearRegression-train-rmse-score: ', rmse(y_train, y_train_pred_lr))\n",
    "print ('LinearRegression-test-rmse-score: ', rmse(y_test, y_test_pred_lr))\n",
    "print ('LinearRegression-train-r2score: ',  r2_score(y_train, y_train_pred_lr))\n",
    "print ('LinearRegression-test-r2score: ', r2_score(y_test, y_test_pred_lr))\n",
    "\n",
    "# OLS评价得分\n",
    "print ('OLS-train-rmse-score: ', rmse(y_train, y_train_pred_ols))\n",
    "print ('OLS-test-rmse-score: ', rmse(y_test, y_test_pred_ols))\n",
    "print ('OLS-train-r2score: ', r2_score(y_train, y_train_pred_ols))\n",
    "print ('OLS-test-r2score: ', r2_score(y_test, y_test_pred_ols))\n",
    "\n",
    "# RidgeCV岭回归评价得分\n",
    "print ('RidgeCV-train-rmse-score: ', rmse(y_train, y_train_pred_ridge))\n",
    "print ('RidgeCV-test-rmse-score: ', rmse(y_test, y_test_pred_ridge))\n",
    "print ('RidgeCV-train-r2score: ', r2_score(y_train, y_train_pred_ridge))\n",
    "print ('RidgeCV-test-r2score: ', r2_score(y_test, y_test_pred_ridge))\n",
    "\n",
    "# LassoCV评价得分\n",
    "print ('LassoCV-train-rmse-score: ', rmse(y_train, y_train_pred_lasso))\n",
    "print ('LassoCV-test-rmse-score: ', rmse(y_test, y_test_pred_lasso))\n",
    "print('LassoCV-train-r2score: ', r2_score(y_train, y_train_pred_lasso))\n",
    "print('LassoCV-test-r2score ', r2_score(y_test, y_test_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 特征系数和测试性能比较\n",
    "# 1、Ridge比OLS的特征系数更优，因为Ridge添加了二阶正则项，是一种缩减算法，能够减少不相关的参数，并且均方差比OLS更稳定。\n",
    "# 2、Lasso的惩罚函数是L1范数，选择剔除系数，而Ridge的惩罚函数是L2，选择缩小系数，L2正则化比L1更能让系数取值更平均。\n",
    "# 3、LassoCV的RMSE值比OLS和RidgeCV较大，但LassoCV的R2性能高于其他。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
